﻿using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace WebUpdaterAdminCore.Data.Migrations
{
    public partial class modify_20180503 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_ClientStatus_ClientInfos_ClientId",
                table: "ClientStatus");

            migrationBuilder.DropPrimaryKey(
                name: "PK_ClientStatus",
                table: "ClientStatus");

            migrationBuilder.DropIndex(
                name: "IX_ClientStatus_ClientId",
                table: "ClientStatus");

            migrationBuilder.AlterColumn<string>(
                name: "ClientId",
                table: "ClientStatus",
                nullable: false,
                oldClrType: typeof(string),
                oldNullable: true);

            migrationBuilder.AddUniqueConstraint(
                name: "AK_ClientStatus_SessionId",
                table: "ClientStatus",
                column: "SessionId");

            migrationBuilder.AddPrimaryKey(
                name: "PK_ClientStatus",
                table: "ClientStatus",
                columns: new[] { "ClientId", "SessionId" });

            migrationBuilder.CreateIndex(
                name: "IX_ClientStatus_ClientId",
                table: "ClientStatus",
                column: "ClientId",
                unique: true);

            migrationBuilder.AddForeignKey(
                name: "FK_ClientStatus_ClientInfos_ClientId",
                table: "ClientStatus",
                column: "ClientId",
                principalTable: "ClientInfos",
                principalColumn: "ClientId",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_ClientStatus_ClientInfos_ClientId",
                table: "ClientStatus");

            migrationBuilder.DropUniqueConstraint(
                name: "AK_ClientStatus_SessionId",
                table: "ClientStatus");

            migrationBuilder.DropPrimaryKey(
                name: "PK_ClientStatus",
                table: "ClientStatus");

            migrationBuilder.DropIndex(
                name: "IX_ClientStatus_ClientId",
                table: "ClientStatus");

            migrationBuilder.AlterColumn<string>(
                name: "ClientId",
                table: "ClientStatus",
                nullable: true,
                oldClrType: typeof(string));

            migrationBuilder.AddPrimaryKey(
                name: "PK_ClientStatus",
                table: "ClientStatus",
                column: "SessionId");

            migrationBuilder.CreateIndex(
                name: "IX_ClientStatus_ClientId",
                table: "ClientStatus",
                column: "ClientId",
                unique: true,
                filter: "[ClientId] IS NOT NULL");

            migrationBuilder.AddForeignKey(
                name: "FK_ClientStatus_ClientInfos_ClientId",
                table: "ClientStatus",
                column: "ClientId",
                principalTable: "ClientInfos",
                principalColumn: "ClientId",
                onDelete: ReferentialAction.Restrict);
        }
    }
}
